package Bidostar_Page;

import Bidostar_BaseData.Page;
import Bidostar_Data.Bidostar_GetCode;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;

import java.util.concurrent.TimeUnit;

public class OperationlogPage extends Page
{
    public OperationlogPage(WebDriver driver)
    {
        super(driver);
    }

    public void clickOperationlog()
    {
        getElement("Operationlog").click();
    }

    public void clickDatelist()
    {
        driver.findElement(By.xpath("html/body/div[1]/div[3]/div/div[1]/div[1]/div/label")).click();
    }

    public void InputDate(String InputData)
    {
        getElement("InputData").clear();
        getElement("InputData").sendKeys(InputData);
    }


    public void InputSearch(String InputSearch)
    {
        getElement("InputSearch").clear();
        getElement("InputSearch").sendKeys(InputSearch);
    }

    public void Search_Btn()
    {
        getElement("Search_Btn").click();
    }

    public boolean Operationlog()
    {
        try
        {
            clickOperationlog();
            logger.info("点击进入『操作历史』页面");
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            clickDatelist();
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            InputDate(UsedDate());
            logger.info("点击输入当天日期：" + UsedDate());
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            getElement("InputData").sendKeys(Keys.chord(Keys.ENTER));
            if (driver.getCurrentUrl().contains("ci.bidostar.com"))
            {
                InputSearch(Bidostar_GetCode.cu_name());
                logger.info("点击输入保险平台登录账户名称:" + Bidostar_GetCode.cu_name());

            } else if (driver.getCurrentUrl().contains("ta.bidostar.com"))
            {
                InputSearch(Bidostar_GetCode.ta_name());
                logger.info("点击输入交警平台登录账户名称:" + Bidostar_GetCode.ta_name());
            } else if (driver.getCurrentUrl().contains("dc.bidostar.com"))
            {
                InputSearch(Bidostar_GetCode.Dc_name());
                logger.info("点击输入调度平台登录账户名称:" + Bidostar_GetCode.Dc_name());
            }
            Search_Btn();
            if (getElement("Search_list").getText().contains("0") && !getElement("Search_list").getText().matches("^.*[1-9]+.*$"))
            {
                logger.warn(getElement("Search_NoList").getText());
            } else
            {
                logger.info("有搜索结果:" + getElement("Search_list").getText());

            }
        } catch (Exception e)
        {
            e.printStackTrace();
            ScreenGet();
        }
        return false;
    }
}
